package biz.ezcom.design.pattern.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 能包含子元素的组件 
 */
public class Component extends Composite{
	private List<Composite> list = new ArrayList<Composite>();
	
	public Component(int level, String name) {
		super(level, name);
	}
	@Override
	public void add(Composite company) {
		list.add(company);
	}

	@Override
	public void remove(Composite company) {
		list.remove(company);
	}

	@Override
	public void show() {
		for(int i=0 ; i<getLevel() ; i++){
			System.out.print("\t");
		}
		System.out.println(getName() + ":");
		for(Composite company : list){
			company.show();
		}
	}
	
}
